package Preferred_algorithm.Topic7_Divide_and_conquer_algorithm;

public class Quick_sort {

    //  快速排序
    //  https://leetcode.cn/problems/sort-an-array/

    int[] nums;
    public void sortColors(int[] _nums) {
        nums = _nums;
        int left = -1 , right = nums.length , i = 0;
        while(i < right){
            if(nums[i] == 0){
                swap(left+1 , i);
                left++;
                i++;
            }else if(nums[i] == 1){
                i++;
            }else{
                swap(right-1 , i);
                right--;
            }
        }
    }
    public void swap(int i , int j){
        int tmp = nums[i];
        nums[i] = nums[j];
        nums[j] = tmp ;
    }
}
